home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / 3d_lib.zip / XROT.C < prev    next >
C/C++ Source or Header  |  1993-05-09  |  2KB  |  57 lines

  1. /* Add rotation about x axis to transformation matrix
  2.  
  3.    Copyright (c) 1988 by Gus O'Donnell
  4.  
  5.    Revision history:
  6.  
  7.    Version 1.00         February 29, 1988       As released.
  8.  
  9.    Version 1.01         March 20, 1988          Created libraries for all
  10.                                                 memory models
  11.  
  12. */
  13. #include "3d.h"
  14. #include <float.h>
  15. #include <math.h>
  16. #include <stdio.h>
  17.  
  18. void    xrot (double theta, MATRIX this_mat)
  19.  
  20. /* Add rotation to the transformation matrix.
  21.  
  22. Vertices may be rotated about any axis.  Note that x rotation is about
  23. the vector i = [1 0 0].  If a rotation about a point local to the object
  24. is desired, the point (and the entire object) must first be translated
  25. to [0 0 0], the rotation performed, and the translation reversed.  This
  26. is accomplished by concatenating these three transformations.
  27.  
  28. The end result of the rotation is
  29.  
  30.    [x y z] -> [x (y cos theta + z sin theta) (z cos theta - y sin theta)]
  31.  
  32. The rotation is clockwise as viewed along the axis of rotation from
  33. the positive direction.  The angle is expressed in radians.
  34.  
  35. The matrix created for the scaling transformation is
  36.  
  37.            |  1.0  0.0         0.0        0.0  |
  38.            |  0.0  cos theta  -sin theta  0.0  |
  39.            |  0.0  sin theta   cos theta  0.0  |
  40.            |  0.0  0.0         0.0        1.0  |
  41.  
  42. The current transformation matrix this_mat is then multiplied by the rotation
  43. transformation matrix, thus concatenating the rotation operation with the
  44. current transformation.
  45. */
  46.  
  47. {
  48.     MATRIX xr_mat;
  49.  
  50.     identity (xr_mat);
  51.     xr_mat [1] [1] = cos(theta);
  52.     xr_mat [1] [2] = -sin(theta);
  53.     xr_mat [2] [1] = sin(theta);
  54.     xr_mat [2] [2] = cos(theta);
  55.     mat_mul (this_mat,xr_mat,this_mat);
  56. }
  57.